package com.api.devices.test;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import java.io.*;

public class CommonsHexReader {
    private static String filePath = "D:\\Project\\demo\\20250515210200.dat";
    public static void main(String[] args) {
//        String filePath = "data.dat";

//        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
            // 跳过第一行
            br.readLine();

            String line;
            Hex hex = new Hex();
            while ((line = br.readLine()) != null) {
                try {
                    // 使用Commons Codec解码HEX字符串
                    byte[] bytes = hex.decode(line.getBytes());

                    // 处理字节数据
                    System.out.println("Decoded bytes: " + java.util.Arrays.toString(bytes));
                } catch (DecoderException e) {
                    System.err.println("Invalid HEX format in line: " + line);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}